import java.beans.IntrospectionException;
import java.beans.PropertyVetoException;
import java.util.Date;

import org.upfrost.Mapper;
import org.upfrost.MapperSession;

import com.mchange.v2.c3p0.ComboPooledDataSource;


public class Main 
{
	static public void main(String[] args) throws PropertyVetoException, IntrospectionException
	{
		// Create a datasource
		ComboPooledDataSource  dataSource = new ComboPooledDataSource();
		dataSource.setDriverClass("org.hsqldb.jdbcDriver");
		dataSource.setJdbcUrl("jdbc:hsqldb:mem:test");
		dataSource.setUser("sa");
		dataSource.setPassword("");
		
		// Initialize the mapper, this is done once in the application
		Mapper mapper = new Mapper(dataSource); 
		mapper.addAnnotated(Test.class);
		
		// Now we can create a session and use it
		MapperSession session = mapper.initSession("test").getSession();
		session.createQuery(TestDAO.CREATE_HSQL).update();
		
		TestDAO tdao = new TestDAO(session);
		
		Test t1 = new Test();
		t1.setName("Rodrigo");
		t1.setEmail("somename@somewhere.tld");
		t1.setCreationDate(new Date());
		
		tdao.insert(t1);
		
		Test rodrigo = tdao.get("Rodrigo");
		System.out.println("Rodrigo's email is " + rodrigo.getEmail());
		
		session.close(); // Do not forget
	}
	
	
}
